package org.ns.framework.datasource.mybatis;

import java.util.Set;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.ns.framework.datasource.database.SegmentMode;
import org.ns.framework.datasource.database.TransactionReference;

/**
 * Mybatis 事物管理. 引用关系
 * @author zhangxingyu
 *
 */
public abstract class MybatisTransactionReference extends TransactionReference
		implements TransactionManage {

	@Override
	protected Set<SegmentMode> getSegmentModes() {
		return super.getSegmentModes();
	}

	@Override
	protected Set<SegmentMode> getChildSegmentMode() {
		return super.getChildSegmentMode();
	}

	@Override
	protected void segment(SegmentMode... segmentModes) {
		super.segment(segmentModes);
	}

	@Override
	protected void setSegmentModes(Set<SegmentMode> segmentModes) {
		super.setSegmentModes(segmentModes);
	}

	@Override
	protected int reference() {
		return super.reference();
	}

	@Override
	protected int release() {
		return super.release();
	}
	
	
	@Override
	protected boolean existSegment(SegmentMode segmentMode) {
		return super.existSegment(segmentMode);
	}

	@Override
	protected void unsegment(SegmentMode... segmentModes) {
		super.unsegment(segmentModes);
	}

	/**
	 * 触发截断
	 */
	@Override
	public MybatisTransactionSegment segment() {
		segment(SegmentMode.tempSegment);
		return new MybatisTransactionSegment(this);
	}
	
	protected void setDefaultAutoCommit(boolean defaultAutoCommit) {
		super.setDefaultAutoCommit(defaultAutoCommit);
	}
	
	protected abstract SqlSession openSession(String dataSourceName, SqlSessionFactory sqlSessionFactory) ;

}
